/**
 * 分类页面
 * @description 展示商品分类列表和分类下的商品
 */
Page({
  data: {
    categories: [
      { id: 1, name: '数码产品', icon: '/images/digital.png' },
      { id: 2, name: '图书教材', icon: '/images/book.png' },
      { id: 3, name: '生活用品', icon: '/images/life.png' },
      { id: 4, name: '服装鞋包', icon: '/images/clothing.png' },
      { id: 5, name: '其他', icon: '/images/other.png' }
    ],
    currentCategory: 1,
    goodsList: [],
    loading: false
  },

  // 切换分类
  switchCategory: function(e) {
    const categoryId = e.currentTarget.dataset.id
    this.setData({
      currentCategory: categoryId,
      goodsList: []
    })
    this.loadCategoryGoods(categoryId)
  },

  // 加载分类商品
  loadCategoryGoods: function(categoryId) {
    this.setData({ loading: true })
    // TODO: 调用获取分类商品接口
    setTimeout(() => {
      const mockGoods = [] // 模拟数据
      this.setData({
        goodsList: mockGoods,
        loading: false
      })
    }, 500)
  }
})